<%--
Copyright (c) 2004-2006 BroadVision, Inc.  All rights reserved.

This software is copyrighted. Under the copyright laws, this software
may not be copied, in whole or in part, without prior written consent
of BroadVision, Inc. or its assignees. This software is provided
under the terms of a license between BroadVision and the recipient,
and its use is subject to the terms of that license.

This software may be protected by one or more U.S. and International
patents.  Certain applications of BroadVision One-To-One software are
covered by U.S. patent 5,710,887.

TRADEMARKS: BroadVision and BroadVision One-To-One are registered
trademarks of BroadVision, Inc., in the United States and the
European Community, and are trademarks of BroadVision, Inc., in other
countries.  The BroadVision logo, is a trademark of BroadVision,
Inc., in the United States and other countries. Additionally, IONA
and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and
RC2 are trademarks of RSA Data Security, Inc.

--%><%@ taglib uri="/WEB-INF/c.tld" prefix="c-p2"
%><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean-p2"
%><%@ taglib uri="/WEB-INF/pager-taglib.tld" prefix="pg2"
%>
<c-p2:if test="${pager2 != null}">

<bean-p2:define id="pager2" name="pager2" type="com.broadvision.web.util.ViewDynaBean" />
<bean-p2:define id="urlParams" name="pager2" property="urlParams" type="java.util.Map"/>

<%
  int count = ((Integer) pager2.get("count")).intValue();
  int maxPageItems = ((Integer) pager2.get("maxPageItems")).intValue();
  String url = org.apache.struts.util.RequestUtils.computeURL(pageContext, null, null, (String) pager2.get("url"), null, null, false);                                                        
%>

<div class="pagination">
<pg2:pager  id="pager2" 
          url="<%= url %>"
        items="<%= count %>"
 maxPageItems="<%= maxPageItems %>"
       export="thisPageNumber=pageNumber">

<%
  java.util.Iterator iter = urlParams.entrySet().iterator();
  while (iter.hasNext()) {
    java.util.Map.Entry param = (java.util.Map.Entry) iter.next();
    String key = (String) param.getKey();
    String value = (String) param.getValue();
%>
  <pg2:param name="<%= key %>" value="<%= value %>"/>
<%
  }
%>

  <pg2:param name="pager2.maxPageItems" value="<%= Integer.toString(maxPageItems) %>"/>

  <pg2:page>
  <script language="JavaScript">

  //
  //
  //
  function replaceValue2(src, needle, value) {
    var start = src.indexOf(needle);
    if (start != -1) {
      var head = src.substr(0, start);
      var rest = src.substr(start + needle.length);

      var numbers = "1234567890";
      var index = 0;
      var peek = rest.charAt(index++);
      while (numbers.indexOf(peek) != -1 && index < rest.length) {
        peek = rest.charAt(index++);
      }

      var tail = "";
      if (index != rest.length) {
        tail = rest.substr(--index);
      }
      src = head + needle + value + tail;
    }
    return src;
  }

  //
  //
  //
  function onChangeMaxPageItems2(selectCtrl) {
    var url = "<%= pageUrl %>";
    var selectedIndex = selectCtrl.selectedIndex;
    if (selectedIndex != -1) {
      var maxPageItems = selectCtrl.options[selectedIndex].value;

      var needle = "pager2.maxPageItems=";
      url = replaceValue2(url, needle, maxPageItems);

      needle = "pager2.offset=";
      url = replaceValue2(url, needle, 0);
    }

    window.location = url;
  }

  </script>
  </pg2:page>

  <c-p2:if test="${pager2.map.showMaxPageItems}">

  <bean-p2:message key="page.itemsPerPage" bundle="mc.messages"/>: <select name="pager2.maxPageItems" size="1" onChange="onChangeMaxPageItems2(this)">
   <option value="10" <%= (maxPageItems == 10) ? "selected" : "" %>><bean-p2:message key="pager.option1" bundle="mc.messages"/></option>
   <option value="20" <%= (maxPageItems == 20) ? "selected" : "" %>><bean-p2:message key="pager.option2" bundle="mc.messages"/></option>
   <option value="30" <%= (maxPageItems == 30) ? "selected" : "" %>><bean-p2:message key="pager.option3" bundle="mc.messages"/></option>
   <option value="50" <%= (maxPageItems == 50) ? "selected" : "" %>><bean-p2:message key="pager.option4" bundle="mc.messages"/></option>
   <option value="100" <%= (maxPageItems == 100) ? "selected" : "" %>><bean-p2:message key="pager.option5" bundle="mc.messages"/></option></select>

  </c-p2:if>

  <pg2:index>
  <pg2:first unless="current"><a href="<%= pageUrl %>" class="paginationBtn"><bean-p2:message key="page.first" bundle="mc.messages"/></a></pg2:first>
  <pg2:prev><a href="<%= pageUrl %>" class="paginationBtn"><bean-p2:message key="page.previous" bundle="mc.messages"/></a></pg2:prev>
  <pg2:last>
<%
  if (thisPageNumber.intValue() > pageNumber.intValue()) {
    thisPageNumber = new Integer(pageNumber.intValue());
  }
%>
  <bean-p2:message key="page.pageOf" bundle="mc.messages" arg0="<%= thisPageNumber.toString() %>" arg1="<%= pageNumber.toString() %>"/></pg2:last>
  <pg2:next><a href="<%= pageUrl %>" class="paginationBtn"><bean-p2:message key="page.next" bundle="mc.messages"/></a></pg2:next>
  <pg2:last unless="current"><a href="<%= pageUrl %>" class="paginationBtn"><bean-p2:message key="page.last" bundle="mc.messages"/></a></pg2:last>
  </pg2:index>

</pg2:pager>
</div>

</c-p2:if>